package com.aierkeji.b2c.utils;

import com.alibaba.druid.util.StringUtils;

import java.util.HashMap;
import java.util.Map;


public class ResultMapHelper {

	public static Map<String, Object> result(String status,String msg,Object data){
		Map<String, Object> result = initMap();
		result.put("status", status);
		result.put("msg", msg);
		result.put("data", data);
		return result;
	}
	
	public static Map<String, Object> result(String status,String msg){
		return result(status, msg, null);
	}
	
	
	public static Map<String, Object> failure(String msg){
		return result(ResultCode.CODE_ERROR, msg, null);
	}
	
	public static Map<String, Object> success(Object obj,String msg){
		return result(ResultCode.CODE_NORMAL, msg, obj);
	}
	
	public static Map<String, Object> success(Object obj){
		return result(ResultCode.CODE_NORMAL, null, obj);
	}
	
	public static Map<String, Object> success(){
		return result(ResultCode.CODE_NORMAL, null, null);
	}
	
	public static boolean isSuccess(Map<String, Object> result){
		String status = result.get("status").toString();
		if(StringUtils.equals(status, ResultCode.CODE_NORMAL)){
			return true;
		}
		return false;
	}
	public static Map<String, Object> permissionDenied(){
		return result(ResultCode.CODE_ERROR_110, "permission denied!");
	}

	public static Map<String, Object> nonLogin(){
		return result(ResultCode.CODE_ERROR_02, "没有找到登录用户");
	}

	public static Map<String, Object> nullParamsResult(){
		return result(ResultCode.CODE_ERROR_01, "相关参数不能为空");
	}
	
	public static Map<String, Object> bizError(String msg){
		return result(ResultCode.CODE_ERROR_100, msg);
	}
	
	public static Map<String,Object> initMap(){
		return new HashMap<>();
	}
	
}